<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="demo"></div>
    <button class="btn">点击</button>
</body>
<script>
    var demo = document.getElementById('demo');
    var btn = document.getElementsByClassName("btn")[0];



    btn.onclick = function () {
        var req = new XMLHttpRequest();  // 0

        req.open("get", "../php/01.php", true);  // 1

        req.send();  // 1

        req.onreadystatechange = function () {
            console.log("readyState", req.readyState);  // 2 3 4
            if (req.readyState == 4 && req.status == 200) {
                console.log(req.responseText);

                // 后端返回的响应数据 可以是 txt/html/xml/json数据(json字符串)
                // var result = req.responseText;
                // demo.innerHTML = result;
            }
        }
    }



</script>

</html>